#include "server.h"
#include <QApplication>

void outputMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg);

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    qInstallMessageHandler(outputMessage);
    Server w;
    w.show();

    return a.exec();
}

void outputMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg)

{
    QString text;

    switch(type)

    {
    case QtDebugMsg:

text = QString("Debug:");

break;
    case QtWarningMsg:

text = QString("Warning:");

break;
    case QtCriticalMsg:

text = QString("Critical:");

break;
    case QtFatalMsg:

text = QString("Fatal:");

    }
    QDateTime current_date_time = QDateTime::currentDateTime();

    QString current_date = current_date_time.toString("yyyy-MM-dd hh:mm:ss ddd");

    QString message = text.append(msg).append("(").append(current_date).append(")");

    QString filename=current_date_time.toString("log_yyyyMMdd");

    filename+=".txt";

    filename="logs/"+filename;

    QFile file(filename);

    file.open(QIODevice::WriteOnly | QIODevice::Append);

    QTextStream text_stream(&file);

    text_stream<<message<<"\r\n";

    file.close();

}
